package com.xxd.dfs.backupnode;

/**
 * @author: XiaoDong.Xie
 * @create: 2020-08-21 09:53
 * @description: 备用接口
 */
public class BackupNode {
    private EditLogTailer editLogTailer;

    private NameNodeRpcClient namenode;

    private StandbyCheckpointer checkpointer;

    private FSNameSystem nameSystem;

    private volatile boolean shouldRun = true;
    private Configuration conf = Configuration.getInstance();
    public BackupNode() {
        namenode = new NameNodeRpcClient();

        nameSystem = new FSNameSystem();
        String fsImageFileName = nameSystem.loadFromDisk(conf);

        checkpointer = new StandbyCheckpointer(nameSystem, namenode,
                fsImageFileName,
                nameSystem.getCheckpointTxid());
        checkpointer.start();

        this.editLogTailer = new EditLogTailer(namenode, nameSystem);
        editLogTailer.start();
    }

    /**
     * 运行DataNode
     */
    private void start() {
        try {
            while (shouldRun) {
                Thread.sleep(1000);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        BackupNode backupNode = new BackupNode();
        backupNode.start();
    }
}
